package com.getpebble.android.main.sections.settings.activity;

import android.app.Fragment;
import android.os.Bundle;
import android.widget.Toast;
import com.getpebble.android.PebbleApplication;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Analytics.MobileAppBehavior;
import com.getpebble.android.framework.developer.PblDeviceObserver.ConnectedDeviceChangeListener;
import com.getpebble.android.main.sections.settings.fragment.LanguageInstallFragment;
import com.getpebble.android.main.sections.support.activity.SingleFragmentActivity;

public class LanguageSelectionActivity extends SingleFragmentActivity implements ConnectedDeviceChangeListener {
    public void onBackPressed() {
        Fragment currentFragment = getCurrentFragment();
        if (currentFragment == null || !(currentFragment instanceof LanguageInstallFragment) || !((LanguageInstallFragment) currentFragment).isInstalling()) {
            super.onBackPressed();
        }
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PebbleApplication.addConnectedDeviceChangeListener(this);
    }

    public void onDestroy() {
        PebbleApplication.removeConnectedDeviceChangeListener(this);
        super.onDestroy();
    }

    public int getLayoutId() {
        return R.layout.activity_language_selection;
    }

    public int getTitleStringId() {
        return R.string.languages_banner;
    }

    public int getActionBarIconId() {
        return R.drawable.ic_drawer_settings;
    }

    public void switchScreenFragment(Fragment fragment) {
        super.switchFragment(fragment);
    }

    public void notifyConnectedDeviceChanged() {
        runOnUiThread(new Runnable() {
            public void run() {
                if (!PebbleApplication.isConnected()) {
                    Toast.makeText(LanguageSelectionActivity.this, R.string.language_selection_pebble_disconnected_toast, 1).show();
                    LanguageSelectionActivity.this.finish();
                }
            }
        });
    }

    public void onResume() {
        super.onResume();
        MobileAppBehavior.logLanguageSettingsOpened();
    }
}
